<? if (!defined("DB_PEREFIX")) exit;

global $db, $template;

$number = 30;
$start = 0;
if (isset($_GET['page']) && $_GET['page'] != "0") 
	$start = (intval ($_GET['page']) - 1) * $number;

// Создаем пустой массив для списка блогов
$blog_top = array();


past_navblock (array (
                      array ('Написать статью', '/blog/addpost/', 'cat', 'add'),
                      array ('Поиск по тегам', '/blog/tags/', 'cat', 'tags'),
                      array ('Комментарии', '/blog/comments/', 'name', 'art_comments'),
                      array ('TOP блогов', '/blog/top/', 'name', 'top'),
                     )
              );


$get = $db->query ('SELECT ac.cat_name, ac.cat_header, ac.cat_rating, ac.cat_users, SUM(a.art_rating) AS rating, COUNT(*) AS count
	FROM '.DB_PEREFIX.'_art_category AS ac
	JOIN '.DB_PEREFIX."_articles AS a ON ( a.art_category = ac.cat_name)
	WHERE a.art_like_page = 'no'
	GROUP BY ac.cat_name
	ORDER BY ac.cat_rating DESC	 
	LIMIT $start, $number;");	

while ($blog = $db->fetch_array ($get)) 
{
        $blog_top[] = $blog;
}

$data = array( 'blog_top' => $blog_top);
load_module_view('blog', 'blog_top',  $data);
	
$count = $db->fetch_row ($db->query ('SELECT count(*) FROM '.DB_PEREFIX.'_art_category'));
if ($count[0] > $number)
{
	loade_helper('page');
	print past_pages($start, $number, $count[0], '/top/');
}
